<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>即时配送订单记录</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  {include file="public/css"/}
</head>
<body>
  <div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-card layui-col-md12">
          <div class="layui-card-header">即时配送订单记录
						{if input('param.isopen')==1}
						<i class="layui-icon layui-icon-close" style="font-size:18px;font-weight:bold;cursor:pointer" onclick="closeself()"></i>
						{/if}
					</div>
          <div class="layui-card-body" pad15>
						<div class="layui-col-md4" style="padding-bottom:10px">
							<button class="layui-btn layui-btn-primary layuiadmin-btn-list" onclick="location.href='{:url('excel')}'+urlEncode(datawhere)">导出EXCEL</button>
							<!-- <button class="layui-btn layui-btn-primary layuiadmin-btn-list" onclick="datadel(0)">删除</button> -->
						</div>
						<div class="layui-form layui-col-md8" style="text-align:right;padding-bottom:10px">
							{if !input('param.psid')}
<!--							<div class="layui-inline">-->
<!--								<label class="layui-form-label" style="width:60px">配送员</label>-->
<!--								<div class="layui-input-block" style="width:120px;margin-left:90px;text-align:left">-->
<!--									<select name="psid">-->
<!--										<option value="">全部</option>-->
<!--										{foreach $psusers as $v}-->
<!--										<option value="{$v.id}">{$v.realname}</option>-->
<!--										{/foreach}-->
<!--									</select>-->
<!--								</div>-->
<!--							</div>-->
							{/if}
							<div class="layui-inline">
								<label class="layui-form-label" style="width:30px">状态</label>
								<div class="layui-input-block" style="width:120px;margin-left:60px;text-align:left">
									<select name="order_status">
										<option value="">全部</option>
										<option value="101">等待分配骑手</option>
										<option value="102">已分配骑手</option>
										<option value="103">商家取消订单</option>
										<option value="201">骑手到店</option>
										<option value="202">骑手取货成功</option>
										<option value="203">取货失败-商家取消</option>
										<option value="204">取货失败-骑手原因</option>
										<option value="205">取货失败-骑手因商家取消</option>
										<option value="301">配送中</option>
										<option value="302">配送完成</option>
										<option value="303">返还-商家取消</option>
										<option value="304">返还-无法联系收货人</option>
										<option value="305">返还-收货人拒收</option>
										<option value="401">返还-成功</option>
										<option value="501">运力系统原因取消</option>
										<option value="502">不可抗拒因素（天气，道路管制等原因）取消</option>
									</select>
								</div>
							</div>
							<div class="layui-inline">
								<button class="layui-btn layuiadmin-btn-replys" lay-submit="" lay-filter="LAY-app-forumreply-search">
									<i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
								</button>
							</div>
						</div>
						<div class="layui-col-md12">
							<table id="tabledata" lay-filter="tabledata"></table>
						</div>
          </div>
        </div>
    </div>
  </div>
	{include file="public/js"/}
	<script>
  var table = layui.table;
	var datawhere = {};
  //数据表
  var tableIns = table.render({
    elem: '#tabledata'
    ,url: "{$Request.url}" //数据接口
    ,page: true //开启分页
    ,cols: [[ //表头
			//{type:"checkbox"},
      {field: 'id', title: 'ID',  sort: true,width:80},
      {field: 'waybill_id', title: '配送单号'},
      {field: 'nickname', title: '下单人',width:150,templet:function(d){
				if(!d.member) return '';
				return '<img src="'+d.member.headimg+'" style="width:40px;height:40px"/> '+d.member.nickname;
      }},
      {field: 'nickname', title: '所属商家',width:120,templet:function(d){
				if(!d.binfo) return '';
				return d.binfo.name;
      }},
      {title: '商品信息',width:240,templet:function(d){
				return d.goodsdata
      }},
      {field: 'ordernum', title: '订单号/下单时间',sort: true,width:160,templet:function(d){ if(d.orderinfo)return d.orderinfo.ordernum +'<div style="color:#080">'+ date('Y年m月d日 H:i',d.orderinfo.createtime)+'</div>'}},
      {field: 'product_price', title: '商品总价/实付款',width:150,templet: '<div><div>总价：￥{{d.orderinfo.product_price}}</div><div style="font-weight:bold">实付：￥{{d.orderinfo.totalprice}}</div></div>'},
      //{field: 'totalprice', title: '实付款'},
      {field: 'address', title: '收货地址',templet: '<div><div style="font-weight:bold">{{d.orderinfo.linkman}} {{d.orderinfo.tel}} </div><div style="line-height:20px;font-size:12px">{{d.orderinfo.area}} {{d.orderinfo.address}}</div></div>'},
      {field: 'paytype', title: '支付方式',width:70,templet:function(d){
			  if(d.orderinfo) return d.orderinfo.paytype
      }},
      {field: 'order_status', title: '配送状态',templet:function(d){
				if(d.order_status==101){
					return '<span style="color:orange">等待分配骑手</span>';
				}else if(d.order_status==102){
					return '<span style="color:green">已分配骑手</span>';
				}else if(d.order_status==103){
					return '<span style="color:#ccc">商家取消订单</span>';
				}else if(d.order_status==201){
					return '<span style="color:green">骑手到店</span>';
				}else if(d.order_status==202){
					return '<span style="color:green">骑手取货成功</span>';
				}else if(d.order_status==203){
					return '<span style="color:red">取货失败-商家取消</span>';
				}else if(d.order_status==204){
					return '<span style="color:red">取货失败-骑手原因</span>';
				}else if(d.order_status==205){
					return '<span style="color:red">取货失败-骑手因商家取消</span>';
				}else if(d.order_status==301){
					return '<span style="">配送中</span>';
				}else if(d.order_status==302){
					return '<span style="color:green">配送完成</span>';
				}else if(d.order_status==303){
					return '<span style="">返还-商家取消</span>';
				}else if(d.order_status==304){
					return '<span style="">返还-无法联系收货人</span>';
				}else if(d.order_status==305){
					return '<span style="">返还-收货人拒收</span>';
				}else if(d.order_status==401){
					return '<span style="color:#999">返还-成功</span>';
				}else if(d.order_status==501){
					return '<span style="color:#999">运力系统原因取消</span>';
				}else if(d.order_status==502){
					return '<span style="color:#999">不可抗拒因素（天气，道路管制等原因）取消</span>';
				}
			}},
      {field: 'ticheng', title: '配送费',templet:function(d){
			  if(d.orderinfo) return d.orderinfo.freight_price;
		  }},
		  {if $bid ===0 }
		  {field: 'ticheng', title: '实际配送费',templet:function(d){
				  if(d.deliverfee) return d.deliverfee;
				  else return '';
			  }},
		  {/if}
      {field: 'operation', title: '操作',templet:function(d){
				var html = '';
				if(d.order_status < 302 && d.order_status != 103){
					html += '<button class="table-btn" onclick="cancel('+d.id+')">取消</button>';
				}
				// else if(d.order_status==4 || d.order_status==10){
				// 	html += '<button class="table-btn" onclick="datadel('+d.id+')">删除</button>';
				// }
				return html;
      }}
    ]]
  });
	//排序
	table.on('sort(tabledata)', function(obj){
		datawhere.field = obj.field;
		datawhere.order = obj.type;
		tableIns.reload({
			initSort: obj,
			where: datawhere
		});
	});
	//检索
	layui.form.on('submit(LAY-app-forumreply-search)', function(obj){
		var field = obj.field
		var olddatawhere = datawhere
		datawhere = field
		datawhere.field = olddatawhere.field
		datawhere.order = olddatawhere.order
		tableIns.reload({
			where: datawhere,
			page: {curr: 1}
		});
	})
	//删除
	function datadel(id){
		var ids = [];
		if(id==0){
			var checkStatus = table.checkStatus('tabledata')
			var checkData = checkStatus.data; //得到选中的数据
			if(checkData.length === 0){
				 return layer.msg('请选择数据');
			}
			for(var i=0;i<checkData.length;i++){
				ids.push(checkData[i]['id']);
			}
		}else{
			ids.push(id);
		}
		layer.confirm('确定要删除吗?',{icon: 7, title:'操作确认'}, function(index){
			//do something
			layer.close(index);
			var index = layer.load();
			$.post("{:url('del')}",{ids:ids},function(data){
				layer.close(index);
				dialog(data.msg,data.status);
				tableIns.reload()
			})
		});
	}
  //取消
  function cancel(id,st){
	  var ids = [];
	  if(id==0){
		  var checkStatus = table.checkStatus('tabledata')
		  var checkData = checkStatus.data; //得到选中的数据
		  if(checkData.length === 0){
			  return layer.msg('请选择数据');
		  }
		  for(var i=0;i<checkData.length;i++){
			  ids.push(checkData[i]['id']);
		  }
	  }else{
		  ids.push(id);
	  }
	  // layer.confirm('确定要取消吗?',{icon: 7, title:'操作确认'}, function(index){
		//   //do something
		//   layer.close(index);
		//   var index = layer.load();
		//   $.post("{:url('setst')}",{ids:ids,st:st},function(data){
		// 	  layer.close(index);
		// 	  dialog(data.msg,data.status);
		// 	  tableIns.reload()
		//   })
	  // });
	  layui.laytpl(sendExpressTpl.innerHTML).render({}, function(html){
		  var sendExpressLayer = layer.open({type:1,title:'取消配送',area:['600px','400px'],content:html,shadeClose:true,btn: ['确定', '取消'],
			  yes:function(){
				  var cancel_reason_id  = '';
				  $("select[name='send_express[]']").each(function(){
					  cancel_reason_id = $(this).val();
				  })
				  var index = layer.load();
				  $.post("{:url('wxOrderCancel')}",{orderid:id,cancel_reason_id:cancel_reason_id},function(res){
					  layer.close(index);
					  dialog(res.msg,res.status);
					  layer.close(sendExpressLayer);
					  tableIns.reload()
				  })
			  }
		  })
	  });
	  layui.form.render(); //更新全部
  }
	</script>
  <script id="sendExpressTpl" type="text/html">
	  <div id="sendExpressDiv" style="margin:0 20px">
		  <div id="sendExpressContent">
			  <div class="layui-form">
				  <div class="layui-form-item" style="margin-top:40px;">
					  <label class="layui-form-label" style="width:60px">选择原因</label>
					  <div class="layui-input-inline" style="width:300px">
						  <select name="send_express[]" style=" height: auto" lay-verify="required" >
							  <option value="1">暂时不需要邮寄</option>
							  <option value="2">价格不合适</option>
							  <option value="3">订单信息有误，重新下单</option>
							  <option value="4">骑手取货不及时</option>
							  <option value="5">骑手配送不及时</option>
							  <option value="6">其他原因</option>
						  </select>
					  </div>
				  </div>
				  <div class="layui-form-mid layui-word-aux">注意：取消会收取一定违约金</div>
			  </div>
		  </div>
	  </div>
  </script>
	{include file="public/copyright"/}
</body>
</html>